Skip to content

.NET: Added support for polymorphic type as workflow output#4485

Merged
peibekwe merged 4 commits intomainfrom
peibekwe/workflow-output-bugfix
Mar 10, 2026
Merged

.NET: Added support for polymorphic type as workflow output#4485
peibekwe merged 4 commits intomainfrom
peibekwe/workflow-output-bugfix

Conversation

@peibekwe
Copy link
Contributor

@peibekwe peibekwe commented Mar 5, 2026

Description

Added support for polymorphic type as workflow output and enable executors to return instance of derived class which inherits from the base class.

Fixes #4134

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

@peibekwe peibekwe self-assigned this Mar 5, 2026
@markwallace-microsoft markwallace-microsoft added .NET workflows Related to Workflows in agent-framework labels Mar 5, 2026
@github-actions github-actions bot changed the title Added support for polymorphic type as workflow output .NET: Added support for polymorphic type as workflow output Mar 5, 2026
@peibekwe peibekwe marked this pull request as ready for review March 5, 2026 00:48
Copilot AI review requested due to automatic review settings March 5, 2026 00:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for workflow outputs to be validated polymorphically so executors can return derived instances when their declared workflow output type is a base class (fixing issue #4134).

Changes:

  • Update executor output validation to accept derived types for declared yield/output types.
  • Add unit tests covering derived, multi-level derived, exact-type, and unrelated-type output behaviors.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
dotnet/src/Microsoft.Agents.AI.Workflows/Executor.cs Adjusts CanOutput logic to validate outputs polymorphically (base-class inheritance).
dotnet/tests/Microsoft.Agents.AI.Workflows.UnitTests/PolymorphicOutputTests.cs Adds regression coverage for derived outputs and ensures unrelated outputs still fail.

@peibekwe peibekwe added this pull request to the merge queue Mar 9, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 9, 2026
@peibekwe peibekwe added this pull request to the merge queue Mar 9, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 9, 2026
@peibekwe peibekwe added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@peibekwe peibekwe added this pull request to the merge queue Mar 10, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 10, 2026
@peibekwe peibekwe added this pull request to the merge queue Mar 10, 2026
Merged via the queue into main with commit a3bfad4 Mar 10, 2026
21 checks passed
@peibekwe peibekwe deleted the peibekwe/workflow-output-bugfix branch March 10, 2026 20:05
davidahmann pushed a commit to davidahmann/agent-framework that referenced this pull request Mar 11, 2026
…t#4485)

* Added support for polymorphic type as workflow output

* Update Linq expression to avoid unnecessary allocations.

* Added caching as per PR comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

.NET workflows Related to Workflows in agent-framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: InvalidOperationException when returning a derived type as workflow output

6 participants